const root = {
    val: "A",
    left: {
        val: "B",
        left: {
            val: "D",
        },
        right: {
            val: "E",
        },
    },
    right: {
        val: "C",
        right: {
            val: "F",
        },
    },
};

function inorderTraversal(root) {
    if (!root) {
        return
    }
    let res = []
    let stack = []
    // 根节点或者栈不为空
    while (root || stack.length) {
        while (root) {
            // 将当前根节点入栈
            stack.push(root)
            // 找到最左侧节点
            root = root.left
        }
        // 将最左侧节点弹出
        let node = stack.pop()
        res.push(node.val)
        root = node.right
    }
    return res
}

console.log(inorderTraversal(root));